package com.zhiyou.util;

import com.zhiyou.entity.PowerCenter;

import java.util.ArrayList;
import java.util.List;

/**
 * @author sanshi
 * @desc
 * @create 2021-09-09 16:10
 */
public class UserUtil extends DBUtil{
    //根据页数进行数据库的查询
    public List<PowerCenter> getPageUsers(int pageIndex){
        int pageSize = 2; //每页显示2条数据
        List<PowerCenter> list = new ArrayList();
        String sql = "select * from sys_user_chnl limit ?,?";
        Object[] params = {(pageIndex-1)*pageSize,pageSize};
        list = new PWUtil().searchByCondition3(sql,params);
        return list;
    }
    //获取总页数
    public int getPages(int pageSize){
        int pages = 0;
        //获取总条数
        String sql = "select count(*) from sys_user_chnl";
        int totalCount = getTotalCount(sql);
        //总条数除以pageSize即可
        if (totalCount%pageSize ==0){
            pages = totalCount/pageSize;
        }else{
            pages = totalCount/pageSize+1;
        }
        return pages;
    }
}
